package com.fancyy.scm.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.fancyy.scm.R;
import com.fancyy.scm.base.BaseActivity;
import com.fancyy.scm.base.http.BRDataListener;
import com.fancyy.scm.base.http.BRDataTransport;
import com.fancyy.scm.databinding.ActivityDeleteCartonFromTrayBinding;
import com.uuzuche.lib_zxing.activity.CaptureActivity;
import com.uuzuche.lib_zxing.activity.CodeUtils;

import static com.fancyy.scm.BRConstant.DELETECARTONFROMTRAY;

public class DeleteCartonFromTray extends BaseActivity<ActivityDeleteCartonFromTrayBinding> {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setNeedScan(true);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_delete_carton_from_tray);
    }
    public  void onScanningClick(View view)
    {
        if(!getPDA()) {
            Intent intent = new Intent(this, CaptureActivity.class);
            startActivityForResult(intent, 1);
        }

    }
    @Override
    public void doScan(String data) {
        BRDataTransport.createPost(DELETECARTONFROMTRAY)
                .addParam("barcode",data)
                .addParam("type","tray")
                .addProgressing(this, "Progressing...")
                .execute(new BRDataListener() {
                    @Override
                    public void onSuccess(Object data) {
                        if ((Boolean)data==true)
                        showToast("Delete Success");
                        else {
                            showToast("The Carton is not exist or has been deleted");
                        }
                    }
                    @Override
                    public void onFail(int status, String failMessage) {
                        showToast("The Carton is not exist or has been deleted");
                    }
                });
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 1 && resultCode == RESULT_OK) {
            String code = data.getStringExtra(CodeUtils.RESULT_STRING);
            BRDataTransport.createPost(DELETECARTONFROMTRAY )
                    .addParam("barcode",code)
                    .addParam("type","tray")
                    .addProgressing(this, "Progressing...")
                    .execute(new BRDataListener() {
                        @Override
                        public void onSuccess(Object data) {
                            showToast("Delete Success");
                        }
                        @Override
                        public void onFail(int status, String failMessage) {
                            showToast("The Carton is not exist or has been deleted");
                        }
                    });
        }
    }
}
